package com.xinyiweidai.xinyiweidai.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.media.tv.TvContentRating;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xinyiweidai.xinyiweidai.R;
import com.xinyiweidai.xinyiweidai.bean.PayListBean;
import com.xinyiweidai.xinyiweidai.util.LabelView;

import java.util.ArrayList;
import java.util.List;

/**
 * classname: $CLASS_NAME$
 * Data：2018/9/25-15:24
 * Author: lanxiong
 * Description:
 */

public class PayHistoryAdapter extends RecyclerView.Adapter<PayHistoryAdapter.ViewHolder> {


    private Context context;
    private List<PayListBean.DataBean> payList = new ArrayList();


    public PayHistoryAdapter(List payList, Context context) {
        this.payList = payList;
        this.context=context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_loan, parent, false));
    }


    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        PayListBean.DataBean bean=payList.get(position);

        holder.tv_loan_money.setText("到账金额: ¥ "+bean.getLoanMoney());
        holder.tv_time_pay.setText("应还款日: "+bean.getBackTime());
        holder.tv_all_pay.setText("到期还款: ¥ "+bean.getBackMoney());
        holder.tv_apply_money.setText("申请金额: ¥ "+bean.getApplyMoney());
        holder.tv_loan_time.setText("放款日期: "+bean.getAuditTime());
        holder.tv_loan_days.setText("放款期限： "+bean.getApplyDay()+"天");
        holder.lv_loan_status.setTextContent(bean.getStatus());

        holder.checkBox_history.setOnCheckedChangeListener((compoundButton, checked) -> {
            holder.tv_apply_money.setVisibility(checked?View.VISIBLE:View.GONE);
            holder.tv_loan_time.setVisibility(checked?View.VISIBLE:View.GONE);
            holder.tv_loan_days.setVisibility(checked?View.VISIBLE:View.GONE);
            holder.checkBox_history.setText(checked?"收起详情":"展开更多");
        });
    }


    @Override
    public int getItemCount() {
        return payList.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_loan_money, tv_time_pay, tv_all_pay;
        private TextView tv_apply_money,tv_loan_time,tv_loan_days;
        private CheckBox checkBox_history;
        private LabelView lv_loan_status;

        private ViewHolder(View itemView) {
            super(itemView);
            this.tv_loan_money = itemView.findViewById(R.id.tv_loan_money);
            this.tv_time_pay = itemView.findViewById(R.id.tv_time_pay);
            this.tv_all_pay = itemView.findViewById(R.id.tv_all_pay);
            this.tv_apply_money = itemView.findViewById(R.id.tv_apply_money);
            this.tv_loan_time = itemView.findViewById(R.id.tv_loan_time);
            this.tv_loan_days = itemView.findViewById(R.id.tv_loan_days);
            this.checkBox_history = itemView.findViewById(R.id.checkBox_history);
            this.lv_loan_status = (LabelView) itemView.findViewById(R.id.lv_loan_status);
        }

    }


}
